package com.caineng.zhaobiao.zbapi.service;

import com.caineng.zhaobiao.zbapi.dao.CaiBaseUserKeywordDao;
import com.caineng.zhaobiao.zbapi.domain.CaiBaseUserKeyword;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户订阅服务类
 * @author liandyao
 * @date 2022/8/24 10:33
 */
@Service
public class CaiBaseUserKeywordService {

    @Autowired
    CaiBaseUserKeywordDao keywordDao;

    /**
     * 根据用户查询订阅信息
     * @param userId
     * @return
     */
    public CaiBaseUserKeyword getByUserId(String userId) {

        CaiBaseUserKeyword keyword = new CaiBaseUserKeyword();
        keyword.setUserId(userId);
        Example<CaiBaseUserKeyword> ex = Example.of(keyword);
        Sort sort = Sort.by(Sort.Order.desc("updateDate"));
        List<CaiBaseUserKeyword> ones = keywordDao.findAll(ex,sort);
        if(ones.size() > 0){
            keyword=ones.get(0);
            return keyword;
        }
        return null ;
    }
}
